package wili.json;

import wili.c.Ca;
import wili.c.Misc9a;

public class JsonArr extends JsonNode {
	public String toString() {
		int n = lineNo2 - lineNo;
		String nlSt = "NL" + n + "=" + this.lineNo2 + "-" + this.lineNo;
		StringBuilder sb = new StringBuilder();
		sb.append("[...], s" + sons.size() + ", " + nlSt);
		return sb.toString();
	}

	public JsonArr(JsonFile0 file, int start, JsonNode dad) {
		super(file, start, dad);
		final String fileSt = file.fileSt;
		JsonNode son;
		for (int i = start + 1; i < endInd - 1; i++) {
			char ch = fileSt.charAt(i);
			switch (ch) {
			case ',':
				continue;
			case '{':
				son = new JsonObj(file, i, this);
				i = son.endInd - 1;
				continue;
			case '[':
				son = new JsonArr(file, i, this);
				i = son.endInd - 1;
				continue;
			case '}':
			case ']':
				Ca.asert(false, fileSt.substring(i));
			case '\"':
				son = new JsonLeaf(file, i, this);
				i = son.endInd - 1;
				continue;
			default:
				if (!Misc9a.isSpaceOrTRN(ch)) {
					son = new JsonLeaf(file, i, this);
					i = son.endInd - 1;
					continue;
				} else {
				}
			}
		}
	}

	@Override
	void saveToBuffer(String dent, StringBuilder buf) {
		buf.append("[");
		String dent2 = dent += "  ";
		for (int i = 0; i < this.sons.size(); i++) {
			JsonNode son = sons.get(i);
			son.saveToBuffer(dent2, buf);
			if (i + 1 < sons.size()) {
				buf.append(",");
			}
		}
		buf.append(dent + "]");
	}
}